package com.code.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.code.dao.BbbMapper;
import com.code.dao.AaaMapper;
import com.code.entity.PageResult;
import com.code.entity.QueryPageBean;
import com.code.pojo.Bbb;
import com.code.pojo.Aaa;
import com.code.service.AaaService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class AaaServiceImpl implements AaaService {

    @Autowired
    AaaMapper aaaMapper;
    @Autowired
    BbbMapper productMapper;


    @Override
    public PageResult<Aaa> findPage(QueryPageBean queryPageBean) {
     PageHelper.startPage(queryPageBean.getPage(),queryPageBean.getSize());
        List<Aaa> aaaList = aaaMapper.findLike(queryPageBean);
        PageInfo<Aaa> pageInfo = new PageInfo<>(aaaList);
        PageResult<Aaa> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return result;

    }
//    @Override
//    public PageResult<Aaa> findPage(Aaa aaa) {
//     PageHelper.startPage(aaa.getPage(),aaa.getSize());
//        List<Aaa> aaaList = aaaMapper.findLike(aaa);
//        PageInfo<Aaa> pageInfo = new PageInfo<>(aaaList);
//        PageResult<Aaa> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
//        return result;
//    }



    @Override
    public Aaa findById(Integer id) {
        return aaaMapper.selectByPrimaryKey(id);
    }

    @Override
    public void add(Aaa aaa) {
        aaaMapper.insert(aaa);
    }

    @Override
    public void update(Aaa aaa) {
        aaaMapper.updateByPrimaryKeySelective(aaa);
    }

    @Override
    public void delete(Integer id) {
        aaaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Bbb> findBbb() {
        return productMapper.selectAll();
    }


//   统计用注解写Sql语句 字段名称为 name  value
    @Override
    public List<Map> tongji() {
        return aaaMapper.tongji();
    }

//    @Override
//    public List<Map> twobzt() {
//        return aaaMapper.twobzt();
////        return null;
//    }

    @Override
    public PageResult<Aaa> findPageNo(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getPage(),queryPageBean.getSize());
        List<Aaa> aaaList = aaaMapper.findPageNo(queryPageBean);
        PageInfo<Aaa> pageInfo = new PageInfo<>(aaaList);
        PageResult<Aaa> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return result;
    }

    @Override
    public void editState(Integer id) {
        Aaa aaa = aaaMapper.selectByPrimaryKey(id);
        aaa.setAid(1);
        aaaMapper.updateByPrimaryKeySelective(aaa);
    }
}
